import apis from '../../http/apis/apis';
export default {
    namespaced: true,
    state: {
        auditTenants: [],
        tenants: [],
        searchType: 'name',
        searchValue: '',
        pages: 0,
        total: 0,
        currentPage: 1,
        pageSize: 5
    },
    getters: {

    },
    mutations: {
        //改变已审核租客的数据
        changeTenantsData(state, tenantsData) {
            state.tenants = tenantsData.tenants;
            state.total = tenantsData.total;
            state.pages = tenantsData.pages;
        },
        //修改查询类型
        changeSearchType(state, searchType) {
            state.searchType = searchType
        },
        //修改查询的值
        changeSearchValue(state, searchValue) {
            state.searchValue = searchValue
        },
        //改变未审核租客的数据
        changeAuditTenantsData(state, auditTenantsData) {
            state.auditTenants = auditTenantsData.auditTenants;
            state.total = auditTenantsData.total;
            state.pages = auditTenantsData.pages;
        },
        //获取要修改的未审核租客
        changeAuditTeanants(state, _id) {
            this.auditTenants._id = _id
        },
        //切换每页显示条数
        changePageSize(state, pageSize) {
            state.pageSize = pageSize
        },
        //切换当前页
        changeCurrentPage(state, currentPage) {
            state.currentPage = currentPage
        },
        //首页
        firstPage(state) {
            state.currentPage = 1
        },
        lastPage(state) {
            state.currentPage = state.pages
        },
        prevPage(state) {
            if (state.currentPage > 1) {
                state.currentPage--
            }
        },
        nextPage(state) {
            if (state.currentPage < state.pages) {
                state.currentPage++
            }
        },
    },
    actions: {
        //获取已审核租客数据
        async getTenants(context) {
            const { data } = await apis.tenants.getTenants({
                searchValue: context.state.searchValue,
                searchType: context.state.searchType,
                currentPage: context.state.currentPage,
                pageSize: context.state.pageSize,
            });
            if (data.status) {
                context.commit('changeTenantsData', data.data)
            }
        },
        //获取未审核租客
        async getAuditTenants(context) {
            const { data } = await apis.tenants.getAuditTenants({
                currentPage: context.state.currentPage,
                pageSize: context.state.pageSize,
            });
            if (data.status) {
                context.commit('changeAuditTenantsData', data.data)
            }
        },
        //获取要修改的未审核租客
        async updateAuditTenants(context, _id) {
            const { data } = await apis.tenants.updateAuditTenants({ _id });
            return data
        }
    }
}